home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk102 / bmorph / biomorph.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  18KB  |  883 lines

  1. /*
  2.             BioMorph
  3.             By:  Chris MacDonald & Steve Martin
  4.             Version:  1.0
  5.             Last Revision:    28 July 89
  6.  
  7.  
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #ifdef LATTICE
  14. #include <proto/all.h>
  15. #include <stdlib.h>
  16. /* Prototypes for functions defined in biomorph.c */
  17. int main(int argc,
  18.      unsigned char **argv);
  19. void mousezoom(unsigned short code);
  20. void genmorph(void);
  21. void analyze(unsigned short Menunumber);
  22. void open_all(void);
  23. void close_all(void);
  24. #endif
  25. #include <exec/types.h>
  26. #include <intuition/intuition.h>
  27. #include <stdio.h>
  28. #include <graphics/gfxmacros.h>
  29. #include <math.h>
  30.  
  31.  
  32. /*
  33. system functions
  34. */
  35.  
  36. extern struct Screen *OpenScreen ();
  37. extern struct Window *OpenWindow();
  38. extern struct Library *OpenLibrary();
  39. extern struct ViewPort *ViewPortAddress();
  40.  
  41.  
  42.  
  43. /*
  44. system variables
  45. */
  46.  
  47. struct IntuitionBase *IntuitionBase;
  48. struct GfxBase *GfxBase;
  49. struct MathBase *MathBase;
  50. struct Screen *s;
  51. struct Window *w;
  52. struct IntuiMessage *msg;
  53. struct RastPort *rp;
  54. struct ViewPort *vp;
  55.  
  56. /*
  57. menu stuff
  58. */
  59.  
  60. struct TextAttr Font =
  61. {
  62.     (STRPTR)"topaz.font",
  63.     TOPAZ_SIXTY,
  64.     FS_NORMAL,
  65.     FPF_ROMFONT
  66. };
  67.  
  68. struct IntuiText GenerateText = {4,1,JAM1,1,1,&Font,
  69.                 (UBYTE *)               "  Generate",NULL};
  70. struct IntuiText StopText ={4,1,JAM1,1,1,&Font,(UBYTE *)"  Stop",NULL};
  71. struct IntuiText QuitText ={4,1,JAM1,1,1,&Font,(UBYTE *)"  Quit",NULL};
  72.  
  73. struct IntuiText GreyText = {4,1,JAM1,1,1,&Font,(UBYTE *) "  Grey",NULL};
  74. struct IntuiText RedText = {4,1,JAM1,1,1,&Font,(UBYTE *)  "  Red",NULL};
  75. struct IntuiText GreenText = {4,1,JAM1,1,1,&Font,(UBYTE *)"  Green",NULL};
  76. struct IntuiText BlueText = {4,1,JAM1,1,1,&Font,(UBYTE *) "  Blue",NULL};
  77.  
  78.  
  79. struct IntuiText TwoText = {4,1,JAM1,1,1,&Font,(UBYTE *)    "   2",NULL};
  80. struct IntuiText FourText = {4,1,JAM1,1,1,&Font,(UBYTE *)   "   4",NULL};
  81. struct IntuiText EightText = {4,1,JAM1,1,1,&Font,(UBYTE *)  "   8",NULL};
  82. struct IntuiText SixteenText = {4,1,JAM1,1,1,&Font,(UBYTE *)"  16",NULL};
  83. struct IntuiText TwentyText = {4,1,JAM1,1,1,&Font,(UBYTE *) "  20",NULL};
  84.  
  85.  
  86. struct IntuiText SquareText ={4,1,JAM1,1,1,&Font,(UBYTE *)"  z^2 + c",NULL};
  87. struct IntuiText CubeText = {4,1,JAM1,1,1,&Font,(UBYTE *) "  z^3 + c",NULL};
  88. struct IntuiText FifthText = {4,1,JAM1,1,1,&Font,(UBYTE *)"  z^5 + c",NULL};
  89.  
  90.  
  91. struct MenuItem Quit =
  92. {
  93.     NULL,1,26,140,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ,
  94.     0,(APTR) &QuitText,NULL,0x51,NULL,0
  95. };
  96.  
  97. struct MenuItem Stop =
  98. {
  99.     &Quit,1,14,140,10,ITEMTEXT | ITEMENABLED | HIGHCOMP |
  100.     CHECKIT | COMMSEQ,0xfffffff9,(APTR) &StopText,NULL,0x53,NULL,0
  101. };
  102.  
  103. struct MenuItem Generate =
  104. {
  105.     &Stop,1,2,140,10,ITEMTEXT | ITEMENABLED | HIGHCOMP |
  106.     CHECKIT | CHECKED | COMMSEQ,0xfffffffa,(APTR) &GenerateText,
  107.     NULL,0x47,NULL,0
  108. };
  109.  
  110.  
  111. struct MenuItem Blue =
  112. {
  113.     NULL,1,38,70,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  114.     | CHECKIT,0xfffffff7,(APTR) &BlueText,NULL,0,NULL,0
  115. };
  116.  
  117. struct MenuItem Green =
  118. {
  119.     &Blue,1,26,70,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  120.     | CHECKIT,0xfffffffb,(APTR) &GreenText,NULL,0,NULL,0
  121. };
  122.  
  123. struct MenuItem Red =
  124. {
  125.     &Green,1,14,70,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  126.     | CHECKIT,0xfffffffd,(APTR) &RedText,NULL,0,NULL,0
  127. };
  128.  
  129. struct MenuItem Grey =
  130. {
  131.     &Red,1,2,70,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKED
  132.     | CHECKIT,0xfffffffe,(APTR) &GreyText,NULL,0,NULL,0
  133. };
  134.  
  135.  
  136. struct MenuItem Twenty =
  137. {
  138.     NULL,1,50,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP | CHECKED
  139.     | CHECKIT,0xffffffef,(APTR) &TwentyText,NULL,0,NULL,0
  140. };
  141.  
  142. struct MenuItem Sixteen =
  143. {
  144.     &Twenty,1,38,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  145.     | CHECKIT,0xfffffff7,(APTR) &SixteenText,NULL,0,NULL,0
  146. };
  147.  
  148. struct MenuItem Eight =
  149. {
  150.     &Sixteen,1,26,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  151.     | CHECKIT,0xfffffffb,(APTR) &EightText,NULL,0,NULL,0
  152. };
  153.  
  154. struct MenuItem Four =
  155. {
  156.     &Eight,1,14,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  157.     | CHECKIT,0xfffffffd,(APTR) &FourText,NULL,0,NULL,0
  158. };
  159.  
  160. struct MenuItem Two =
  161. {
  162.     &Four,1,2,60,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  163.     | CHECKIT,0xfffffffe,(APTR) &TwoText,NULL,0,NULL,0
  164. };
  165.  
  166.  
  167. struct MenuItem Fifth =
  168. {
  169.     NULL,1,26,100,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  170.     | CHECKIT,0xfffffffb,(APTR) &FifthText,NULL,0,NULL,0
  171. };
  172.  
  173. struct MenuItem Cube =
  174. {
  175.     &Fifth,1,14,100,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  176.     | CHECKED | CHECKIT,0xfffffffd,(APTR) &CubeText,NULL,0,NULL,0
  177. };
  178.  
  179. struct MenuItem Square =
  180. {
  181.     &Cube,1,2,100,10,ITEMTEXT | ITEMENABLED | HIGHCOMP
  182.     | CHECKIT,0xfffffffe,(APTR) &SquareText,NULL,0,NULL,0
  183. };
  184.  
  185.  
  186.  
  187.  
  188. struct Menu Zx = {NULL,165,0,80,0,NULL,(BYTE *) "Equation",&Square};
  189. struct Menu Zoom = {&Zx,115,0,50,0,NULL,(BYTE *) "Zoom",&Two};
  190. struct Menu Colors = {&Zoom,55,0,60,0,MENUENABLED,(BYTE *) "Colors",&Grey};
  191. struct Menu File = {&Colors,10,0,45,10,MENUENABLED,
  192.             (BYTE *) "File",&Generate};
  193.  
  194.  
  195.  
  196. /*
  197. voidoids
  198. */
  199.  
  200. void open_all(), close_all(), initmenu();
  201. void addplex(),multplex(),sqrplex(),cubeplex(),analyze(),genmorph();
  202. void mousezoom();
  203.  
  204.  
  205.  
  206. /*
  207. window and screen  (windscreen?)
  208. */
  209.  
  210. struct NewScreen myScreen =
  211. {
  212.     0,0,
  213.     320,200,
  214.     4,
  215.     1,0,
  216.     0,
  217.     CUSTOMSCREEN,
  218.     NULL,
  219.     (UBYTE *)"BioMorph 1.0",
  220.     NULL,
  221.     NULL
  222. };
  223.  
  224.  
  225. struct NewWindow myWindow =
  226. {
  227.       80,9,
  228.       165, 160,
  229.       0,
  230.       1,
  231.       MENUPICK | MOUSEBUTTONS,
  232.       SMART_REFRESH | ACTIVATE | WINDOWSIZING |
  233.       WINDOWDRAG | GIMMEZEROZERO,
  234.       NULL,
  235.       NULL,
  236.       (UBYTE *)"z^3 + c",
  237.       NULL,
  238.       NULL,
  239.       50, 40,
  240.       210, 200,
  241.       WBENCHSCREEN
  242. };
  243.  
  244.  
  245. /*
  246. color maps
  247. */
  248.  
  249.  
  250. UWORD greycolortable[] =
  251. {
  252.     0x004,0xfff,0x990,0x059,
  253.     0x666,0x777,0x888,0x999,
  254.     0xaaa,0xbbb,0xccc,0xddd,
  255.     0xeee,0xfff,0x000
  256. };
  257.  
  258. UWORD redcolortable[] =
  259. {
  260.     0x004,0xfff,0x990,0x059,
  261.     0x600,0x700,0x800,0x900,
  262.     0xa00,0xb00,0xc00,0xd00,
  263.     0xe00,0xf00,0x000
  264. };
  265.  
  266. UWORD greencolortable[] =
  267. {
  268.     0x004,0xfff,0x990,0x059,
  269.     0x060,0x070,0x080,0x090,
  270.     0x0a0,0x0b0,0x0c0,0x0d0,
  271.     0x0e0,0x0f0,0x000
  272. };
  273.  
  274. UWORD bluecolortable[] =
  275. {
  276.     0x004,0xfff,0x990,0x059,
  277.     0x006,0x007,0x008,0x009,
  278.     0x00a,0x00b,0x00c,0x00d,
  279.     0x00e,0x00f,0x000
  280. };
  281.  
  282. /*
  283. IDCMP stuff
  284. */
  285.  
  286. struct IntuiMessage *message;
  287. USHORT MessageClass, MessageCode, MousX, MousY;
  288.  
  289.  
  290.  
  291.  
  292. /*
  293. global variable descriptions
  294.  
  295.  
  296.     creal,      =    real & imaginary portion of
  297.     cimag        constant
  298.  
  299.     magfactor =    magnification factor of graph
  300.  
  301.     fnum      =    function power value (2 = square,
  302.             3 = cube, 4 = z ^ 5)
  303.  
  304.     stopflag  =    flag which tells genmorph() to
  305.             quit when Stop is selected from
  306.             File menu
  307.  
  308.     minwinx,  =    minimum window size values, set
  309.     minwiny     to insure user can't size window
  310.             down while generating graph
  311.  
  312.     winx,      =    size of window user selects for
  313.     winy        next graph
  314.  
  315.     mxstart,  =    upper left corner value for mouse
  316.     mystart     zoom box.  transferred to xstart, ystart
  317.             in genmorph()
  318.  
  319.     xstart,   =    upper left corner value of last generated
  320.     ystart        or currently generating graph
  321.  
  322.     increment =    distance between adjacent graph points
  323.  
  324.     size      =    size in pixels of most recently computed
  325.             or currently computing graph
  326.  
  327. */
  328.  
  329.  
  330. float creal, cimag, magfactor, xstart, ystart, mxstart, mystart, increment;
  331. short fnum,stopflag,minwinx,minwiny,winx,winy,size;
  332.  
  333.  
  334.  
  335. main(argc,argv)
  336. int argc;
  337. UBYTE *argv[];
  338. {
  339. /*
  340. user can enter a '?' or a complex constant
  341. when starting the program
  342. */
  343.  
  344.     printf("\nBioMorph 1.0\n\nby Chris MacDonald & Steve Martin\n\n");
  345.  
  346.     if (argc == 1)    /* no arguments */
  347.     {
  348.         creal = 0.5;
  349.         cimag = 0.0;
  350.  
  351.         printf("Using default constant:   real      = 0.5\n");
  352.         printf("                          imaginary = 0.0\n\n");
  353.         printf("Next time, try your own constant!\n\n");
  354.         printf("Usage:  Biomorph (real) (imaginary)\n");
  355.         printf("Where real and imaginary are a complex constant\n\n");
  356.         Delay(125);
  357.     }
  358.     else if (argc == 2 && (*argv[1] == '?'))   /* user types '?' */
  359.     {
  360.         printf("\nUsage:  Biomorph (real) (imaginary)\n");
  361.         printf("Where real and imaginary are a complex constant\n\n");
  362.         exit(TRUE);
  363.     }
  364.     else
  365.     {
  366.         creal = atof(argv[1]);   /* user enters complex constant */
  367.         cimag = 0.0;
  368.         if(argc >= 3) cimag = atof(argv[2]);
  369.         printf("\nComplex constant:\n");
  370.         printf("real      = %f\n",creal);
  371.         printf("imaginary = %f\n\n",cimag);
  372.         Delay(130);
  373.     }
  374.  
  375.     open_all();              /* opens libraries, screen and window */
  376.  
  377.     LoadRGB4(vp,&greycolortable[0],15);     /* load color table */
  378.  
  379.     SetRast(rp,3);                          /* clear window */
  380.  
  381.             /* default graph drawn when program starts */
  382.     magfactor = 20;
  383.  
  384.             /*where upper left corner of graph should be */
  385.     mxstart = -1.0 * magfactor / 2.0;
  386.     mystart = mxstart;
  387.  
  388.     fnum = 3;            /* function is cube (z^3 + c) */
  389.     genmorph();                     /* generate graph */
  390.  
  391.  
  392.             /* loop which waits for user to access menu */
  393.     while (1)
  394.     {
  395.         if((message = (struct IntuiMessage *)
  396.             GetMsg(w->UserPort)) == NULL)
  397.         {
  398.             Wait(1L << w->UserPort->mp_SigBit);
  399.             continue;
  400.         }
  401.         stopflag = 0;
  402.         MessageClass = message->Class; /* get needed data */
  403.         MessageCode = message->Code;
  404.         MousX = w->GZZMouseX;
  405.         MousY = w->GZZMouseY;
  406.         ReplyMsg((void *)message);              /* respond to message */
  407.  
  408.         switch(MessageClass)
  409.         {
  410.             case MENUPICK :     analyze(MessageCode);
  411.             break;                   /* accessed menu */
  412.  
  413.             case MOUSEBUTTONS :    mousezoom(MessageCode);
  414.             break;             /* pressed mouse button */
  415.         }
  416.  
  417.     }
  418.  
  419. }
  420.  
  421.  
  422.  
  423.  
  424. /*
  425. mousezoom()'s purpose is to generate a "zoom box" while mouse button is
  426. pressed and held down.    When the button is released, the starting
  427. coordinates and magnification of the selected box are computed.
  428. */
  429.  
  430. /*        mousezoom variable descriptions
  431.  
  432.     loop    =    flag indicating end of zoom
  433.             box loop
  434.  
  435.     setx,    =    the starting window coordinates
  436.     sety        of the zoom box
  437.  
  438.     mx    =    x distance mouse moves from setx
  439. */
  440.  
  441.  
  442. void mousezoom(code)
  443. USHORT code;        /* message code  */
  444. {
  445.     short loop = 1;
  446.     USHORT mx,setx,sety;
  447.  
  448.     switch(code)
  449.     {
  450.         case SELECTDOWN :            /*left button down*/
  451.  
  452.             setx = MousX;        /*set starting point of*/
  453.             sety = MousY;        /*zoom box           */
  454.  
  455.             if(setx >= 215) setx = 0;  /*fixes problem when mouse*/
  456.             if(sety >= 215) sety = 0;  /*points to left | up edge*/
  457.  
  458.             mx = w->GZZMouseX;    /*get current mouse x position*/
  459.  
  460.             SetWindowTitles(w,"Zooming!",(void *)-1);
  461.  
  462.             SetDrMd(rp,COMPLEMENT); /* "self erasing" mode*/
  463.             SetAPen(rp,1);
  464.             Move(rp,setx,sety);             /*  draw the zoom box */
  465.             Draw(rp,mx,sety);
  466.             Draw(rp,mx,sety + mx - setx);
  467.             Draw(rp,setx,sety + mx -setx);
  468.             Draw(rp,setx,sety);
  469.  
  470.             while (loop)    /*adjusts zoom box while button down*/
  471.  
  472.             {
  473.                 while((message = (struct IntuiMessage *)
  474.                     GetMsg(w->UserPort)) == NULL)
  475.                 {
  476.                     Move(rp,setx,sety);   /* erase old box */
  477.                     Draw(rp,mx,sety);
  478.                     Draw(rp,mx,sety + mx - setx);
  479.                     Draw(rp,setx,sety + mx -setx);
  480.                     Draw(rp,setx,sety);
  481.  
  482.                     mx = w->GZZMouseX;  /* get new x value */
  483.  
  484.                     /*stops dragging box to the left*/
  485.                     if((mx < setx) || (mx > 400)) mx = setx;
  486.  
  487.                     Move(rp,setx,sety);  /* draw new box */
  488.                     Draw(rp,mx,sety);
  489.                     Draw(rp,mx,sety + mx - setx);
  490.                     Draw(rp,setx,sety + mx -setx);
  491.                     Draw(rp,setx,sety);
  492.  
  493.                 }
  494.                 MessageClass = message->Class; /*drops out of loop*/
  495.                 MessageCode = message->Code;   /*when a message   */
  496.                 ReplyMsg((void *)message);             /*occurs           */
  497.  
  498.                 switch(MessageClass)
  499.  
  500.                 {
  501.                     case MOUSEBUTTONS:
  502.  
  503.                     switch(MessageCode)
  504.  
  505.                     {
  506.                     case SELECTUP:     /* user releases button */
  507.  
  508.                 /* set new mag & position based on zoom box */
  509.                     magfactor =(mx - setx) * increment;
  510.                     mxstart = xstart +
  511.                           ((setx - 2) * increment);
  512.                     mystart = ystart +
  513.                           ((sety - 1) * increment);
  514.  
  515.                     SetWindowTitles(w,"Got it.",(void *) -1);
  516.                     Delay(20);
  517.  
  518.                     switch(fnum)  /* put window title back */
  519.                     {
  520.                     case 2:
  521.                     SetWindowTitles(w,"z^2 + c",(void *) -1);
  522.                     break;
  523.  
  524.                     case 3:
  525.                     SetWindowTitles(w,"z^3 + c",(void *) -1);
  526.                     break;
  527.  
  528.                     case 4:
  529.                     SetWindowTitles(w,"z^5 + c",(void *) -1);
  530.                     break;
  531.                     }
  532.  
  533.                     Move(rp,setx,sety);  /* erase box */
  534.                     Draw(rp,mx,sety);
  535.                     Draw(rp,mx,sety + mx - setx);
  536.                     Draw(rp,setx,sety + mx -setx);
  537.                     Draw(rp,setx,sety);
  538.  
  539.                     loop = 0;   /* set flag to end loop */
  540.                     break;
  541.                     }
  542.                     break;
  543.  
  544.                 }
  545.             }
  546.     }
  547. }
  548.  
  549.  
  550.  
  551. void genmorph()
  552. {
  553.  
  554. /*
  555.     x,    =    graph loop vars. derived from
  556.     y        current window size
  557.  
  558.     n    =    iteration loop variable
  559.  
  560.     value    =    contains result of window sizing
  561.             call
  562.  
  563.     zreal,    =    current equation coordinates
  564.     zimag
  565.  
  566.     a, b    =    temporary storage for math routines
  567.  
  568. */
  569.  
  570.  
  571.     short x,y,n,value;
  572.     float zreal,zimag,a,b;
  573.  
  574.     SetDrMd(rp,JAM1);
  575.  
  576.     stopflag = 0;    /* flag to stop generating */
  577.  
  578.     /* setting limits of window size */
  579.     winx = w->Width;
  580.     winy = w->Height;
  581.     value = WindowLimits(w,winx,winy,210,200);
  582.  
  583.     /* how large the graph should be, based on window size */
  584.     if(winx < winy)
  585.     {
  586.         size = winx - 8;
  587.     }
  588.     else
  589.     {
  590.         size = winy - 8;
  591.     }
  592.  
  593.     /* how much zreal&imag should be incremented each
  594.        time through loop                  */
  595.     increment = magfactor / size;
  596.  
  597.     xstart = mxstart;    /* assign mousezoom() values */
  598.     ystart = mystart;
  599.  
  600.  
  601.     for(y = 0; y <= size - 6; ++y)   /* y graph loop */
  602.     {
  603.         for(x = 0; x <= size; ++x)   /* x graph loop */
  604.         {
  605.             /* setting z value for current coordinates */
  606.             zreal = ((float) xstart + (increment * x));
  607.             zimag = ((float) ystart + (increment * y));
  608.  
  609.             /* iteration loop */
  610.             for(n = 1; n <= 10; ++n)
  611.             {
  612.                 a = zreal;
  613.                 b = zimag;
  614.  
  615.                 if (fnum == 2)    /* square */
  616.                 {
  617.                     zreal = a*a - b*b + creal;
  618.                     zimag = 2*a*b + cimag;
  619.                 }
  620.  
  621.                 else if (fnum == 3)   /* cube */
  622.                 {
  623.                     zreal = a*(a*a - 3*b*b) + creal;
  624.                     zimag = b*(3*a*a - b*b) + cimag;
  625.                 }
  626.  
  627.                 else if (fnum == 4)   /* fifth */
  628.                 {
  629.                     a = zreal;
  630.                     b = zimag;
  631.  
  632.         zreal = a * (a*a*a*a - 10*a*a*b*b + 5*b*b*b*b) + creal;
  633.         zimag = b * (5*a*a*a*a - 10*a*a*b*b + b*b*b*b) + cimag;
  634.                 }
  635.  
  636.  
  637.     /* break out of loop if result is ever greater than ten */
  638.  
  639.                 if(fabs(zreal) > 10 || fabs(zimag) > 10 ||
  640.                     (zreal*zreal + zimag*zimag) > 100)
  641.                     break;
  642.             }
  643.  
  644.  
  645.     /* setting color of pixel based on value of z after iteration */
  646.  
  647.             if(!(fabs(zreal) < 10 || fabs(zimag) < 10))
  648.             {
  649.                 SetAPen(rp,14);
  650.             }
  651.             else if(fabs(zreal) < fabs(zimag))
  652.             {
  653.                 SetAPen(rp,((short) fabs(zreal)) + 4);
  654.             }
  655.             else
  656.             {
  657.                 SetAPen(rp,((short) fabs(zimag)) + 4);
  658.             }
  659.             WritePixel(rp,x,y);
  660.         }
  661.  
  662.  
  663.         /* test for menu access at end of each x loop */
  664.         /* clears all messages except newest          */
  665.         MessageClass = NULL;
  666.         while(message = (struct IntuiMessage *)GetMsg(w->UserPort))
  667.         {
  668.             MessageClass = message->Class;
  669.             MessageCode = message->Code;
  670.             ReplyMsg((void *)message);
  671.         }
  672.  
  673.         if(MessageClass)
  674.         {
  675.             switch(MessageClass)
  676.             {
  677.                 case MENUPICK : analyze(MessageCode);
  678.                 break;
  679.             }
  680.         }
  681.  
  682.  
  683.         /* quit generating if user picks Stop from File menu */
  684.         if(stopflag)
  685.         {
  686.             stopflag = 0;
  687.             x = size;
  688.             y = size - 6;
  689.         }
  690.  
  691.     }
  692.  
  693.     /* set window size limits back to normal */
  694.     value = WindowLimits(w,50,40,210,200);
  695.  
  696.     /* enable zoom and power menus */
  697.     ClearMenuStrip(w);
  698.     Zx.Flags = MENUENABLED;
  699.     Zoom.Flags = MENUENABLED;
  700.     Stop.Flags |= CHECKED;         /* set Stop checkmark */
  701.     Generate.Flags = ITEMTEXT | ITEMENABLED | HIGHCOMP
  702.     | COMMSEQ | CHECKIT;         /* unset Generate checkmark */
  703.     SetMenuStrip(w,&File);
  704.     DisplayBeep(NULL);           /* flash screen when done */
  705.  
  706. }
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714. /*
  715. analyze():  responds to user menu access
  716. */
  717.  
  718. void analyze(Menunumber)
  719. USHORT Menunumber;
  720. {
  721.     USHORT Menu, MenuItem;
  722.  
  723.     Menu = MENUNUM(Menunumber);
  724.     MenuItem = ITEMNUM(Menunumber);
  725.  
  726.     switch(Menu)
  727.     {
  728.         case 0    : /* File Menu */
  729.             switch(MenuItem)
  730.             {
  731.                 case 0    : /* Generate */
  732.                     if (!(stopflag))
  733.                     {
  734.                         SetRast(rp,0);
  735.                         ClearMenuStrip(w);
  736.                         Zoom.Flags = NULL;
  737.                         Zx.Flags = NULL;
  738.                         SetMenuStrip(w,&File);
  739.                         genmorph();
  740.                     }
  741.                     break;
  742.  
  743.                 case 1    : /* Stop */
  744.                     stopflag = 1;
  745.                     ClearMenuStrip(w);
  746.                     Zoom.Flags = MENUENABLED;
  747.                     Zx.Flags = MENUENABLED;
  748.                     SetMenuStrip(w,&File);
  749.                     break;
  750.  
  751.                 case 2    : /* Quit */
  752.                     close_all();
  753.                     exit(TRUE);
  754.                     break;
  755.             }
  756.         break;
  757.  
  758.         case 1    : /* Colors */
  759.             switch(MenuItem)
  760.             {
  761.                 case 0    : /* Grey */
  762.                     LoadRGB4(vp,&greycolortable[0],15);
  763.                     break;
  764.  
  765.                 case 1    : /* Red */
  766.                     LoadRGB4(vp,&redcolortable[0],15);
  767.                     break;
  768.  
  769.                 case 2    : /* Green */
  770.                     LoadRGB4(vp,&greencolortable[0],15);
  771.                     break;
  772.  
  773.                 case 3    : /* Blue */
  774.                     LoadRGB4(vp,&bluecolortable[0],15);
  775.                     break;
  776.             }
  777.         break;
  778.  
  779.         case 2    : /* Zoom */
  780.             switch(MenuItem)
  781.             {
  782.                 case 0    :
  783.                     magfactor = 2;
  784.                     mxstart = -1.0 * magfactor / 2.0;
  785.                     mystart = mxstart;
  786.                     break;
  787.  
  788.                 case 1    :
  789.                     magfactor = 4;
  790.                     mxstart = -1.0 * magfactor / 2.0;
  791.                     mystart = mxstart;
  792.                     break;
  793.  
  794.                 case 2    :
  795.                     magfactor = 8;
  796.                     mxstart = -1.0 * magfactor / 2.0;
  797.                     mystart = mxstart;
  798.                     break;
  799.  
  800.                 case 3    :
  801.                     magfactor = 16;
  802.                     mxstart = -1.0 * magfactor / 2.0;
  803.                     mystart = mxstart;
  804.                     break;
  805.  
  806.                 case 4    :
  807.                     magfactor = 20;
  808.                     mxstart = -1.0 * magfactor / 2.0;
  809.                     mystart = mxstart;
  810.                     break;
  811.             }
  812.         break;
  813.  
  814.         case 3    : /* Power */
  815.             switch(MenuItem)
  816.             {
  817.                 case 0    :
  818.                     fnum = 2;
  819.                     SetWindowTitles(w,"z^2 + c",(void *) -1);
  820.                     break;
  821.  
  822.                 case 1    :
  823.                     fnum = 3;
  824.                     SetWindowTitles(w,"z^3 + c",(void *) -1);
  825.                     break;
  826.  
  827.                 case 2    :
  828.                     fnum = 4;
  829.                     SetWindowTitles(w,"z^5 + c",(void *) -1);
  830.                     break;
  831.             }
  832.         break;
  833.  
  834.     }
  835. }
  836.  
  837.  
  838.  
  839. void open_all()
  840. {
  841.     if((IntuitionBase = (struct IntuitionBase *)
  842.         OpenLibrary("intuition.library", 0L)) == NULL)
  843.             exit(1);
  844.     if((MathBase = (struct MathBase *)
  845.         OpenLibrary("mathffp.library", 0L)) == NULL)
  846.             exit(1);
  847.     if ((GfxBase = (struct GfxBase *)
  848.         OpenLibrary("graphics.library", 0L)) == NULL)
  849.             exit(1);
  850.  
  851. if ((s = OpenScreen(&myScreen)) == NULL)
  852.     exit(1);
  853.  
  854. vp = &(s -> ViewPort);
  855.  
  856. myWindow.Screen = s;
  857. myWindow.Type = CUSTOMSCREEN;
  858.  
  859.     if ((w = OpenWindow(&myWindow)) == NULL)
  860.         exit(1);
  861.     rp = w->RPort;
  862.  
  863.     SetMenuStrip(w,&File);
  864. }
  865.  
  866.  
  867.  
  868.  
  869. void close_all()
  870. {
  871.     while(message = (struct IntuiMessage *)GetMsg(w->UserPort))
  872.     {
  873.         ReplyMsg((void *)message);
  874.     }
  875.  
  876.     if (w) ClearMenuStrip(w);
  877.     if (w) CloseWindow(w);
  878.     if (s) CloseScreen(s);
  879.     if (GfxBase) CloseLibrary(GfxBase);
  880.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  881. }
  882.  
  883.